/*
 * Copyright (C) 2015 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

@import "pages/wiki_animations.scss";
@import "pages/shared/menu_tools.scss";

$subdued-text-color: #696969;
$darkened-text-color: #4d4d4d;

$published-text-color: $ic-color-success;
$unpublished-text-color: $ic-font-color--subdued;
$published-icon-color: $ic-color-success;
$unpublished-icon-color: $ic-font-color--subdued;

$border-color: $ic-border-light;
$border-radius: $baseBorderRadius;

$pages-border: 1px solid $ic-border-light;
$pages-dashed-border: 1px dashed $ic-border-light;
$pages-inner-border: 1px solid $ic-border-light;

$index-background: $ic-color-light;
$item-background: $lightBackground;

$shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
$table-shadow: 0 1px 0 #dde0e4;

$revision-sidebar-width: 270px;
$revision-sidebar-background-color: $ic-body-background-color;
$revision-sidebar-selected-color: #ffffff;
$revision-sidebar-hover-color: lighten($ic-color-neutral, 10);
$revision-sidebar-dimmed-color: $ic-dim-helper-text;
$revision-button-color: $ic-color-dark;

.pages .sticky-toolbar .sticky {
  position: fixed;
  z-index: 1000;
  top: 0px;
  left: 0px;
  right: 0px;
  margin-left: 1px;
  background: white;
  height: 33px;
  max-width: $max_main_width;
  border-color: darken($ic-border-color, 10);
}

.pages.with-left-side .sticky-toolbar .sticky {
  margin-left: $left_side_width + 1px;
}

.pages.with-right-side .sticky-toolbar .sticky {
  margin-right: $right_side_width + 1px;
}

.delete_criterion_link {
  border: none;
  background: none;
  padding: 0px;
}

.add_prerequisite_or_requirement_link {
  color: $ic-link-color;
  border: none;
  background: none;
  padding: 0px;
  &:hover {
    color: $ic-link-color-darkened-10;
    background: none;
    text-decoration: underline;
  }
}

.pages {
  .header-bar-outer-container {
    min-height: 64px;
    clear: right;
    .header-bar-container {
      min-width: $min_main_width - 2px;
      min-height: 64px;
      .page-changed-alert {
        overflow: hidden;
        height: 0;
      }
      .page-changed-alert .alert {
        border-radius: 0;
      }
      .header-left-flex {
        flex: 1;
        float: none;
        white-space: nowrap;
        overflow: hidden;
        .course-title {
          text-overflow: ellipsis;
          overflow: hidden;
        }
      }
      .header-right-flex {
        padding-left: $ic-sp;
      }
      .flex-container {
        display: flex;
        align-items:center {}
      }
    }
  }
  .header-bar-outer-container.page-changed {
    height: 103px;
    animation: page-changed-header-bar 1.15s;
    .header-bar-container {
      height: 103px;
      animation: page-changed-header-bar 1.15s;
      .page-changed-alert {
        margin: (-1px) 0 0 0;
        border-bottom: $pages-border;
        box-shadow: $shadow;
        height: 39px;
        animation: page-changed-alert 1.15s;
      }
    }
  }
}

.pages.index {
  .index-content-container {
    margin-top: 1px;
  }
  .page-edit-dialog .edit-content {
    margin: 8px 5px;
    .edit-label {
      padding-top: 5px;
      width: 75px;
      float: left;
      text-align: right;
    }
    .edit-controls {
      margin-left: 85px;
    }
    .edit-control-text {
      width: 270px;
    }
  }
  .index-content {
    .table {
      margin-bottom: 0;
      border-collapse: separate;
      border-spacing: 0;
      td, th {
        &:first-child {
          padding-left: 12px;
        }
        &:last-child {
          padding-right: 12px;
        }
      }

    }
    .table thead {
      background: $index-background;
      tr {
        height: 40px;
      }
      th {
        vertical-align: middle;
        font-weight: bold;
      }
    }
    .table tbody {
      .page_title {
        font-weight: bold;
      }
      .front-page {
        margin: auto 0.5em;
      }
      tr {
        background: $item-background;
        text-decoration: inherit;
        color: inherit;
        &.clickable:hover {
          background: $ic-list-item-background--hover;
          text-decoration: inherit;
          color: inherit;
        }
        td:first-child {
          border-left: $pages-border;
        }
        td:last-child {
          border-right: $pages-border;
        }
      }
      tr:first-child {
        td {
          border-top: $pages-border;
        }
        td:first-child {
          border-top-left-radius: $border-radius;
        }
        td:last-child {
          border-top-right-radius: $border-radius;
        }
      }
      tr:last-child {
        td {
          border-bottom: $pages-border;
        }
        td:first-child {
          border-bottom-left-radius: $border-radius;
        }
        td:last-child {
          border-bottom-right-radius: $border-radius;
        }
      }
      td {
        @include fontSize(11px);
        color: $subdued-text-color;
        border-top: $pages-inner-border;
        vertical-align: middle;
        line-height: 1.5;
        .wiki-page-link {
          @include fontSize(13px);
          color: $darkened-text-color;
          font-weight: bold;
        }
        .wiki-page-link.published {
          color: $published-text-color;
        }
        .wiki-page-link.unpublished {
          color: $unpublished-text-color;
        }
        .icon-publish {
          color: $published-icon-color;
        }
        .icon-unpublished {
          color: $ic-icon-link-color;
        }
      }
    }
    .table .no-pages .no-pages-cell {
      border: $pages-dashed-border;
    }
    .loading {
      text-align: center;
      color: #8f9295;
      img {
        margin-top: -3px;
        opacity: 0.75;
      }
      &.loading {
        border: 1px solid transparent;
      }
      &.loading-more {
        border: $pages-dashed-border;
        border-top-width: 0;
        border-bottom-left-radius: $border-radius;
        border-bottom-right-radius: $border-radius;
        margin-top: 1px;
        padding: 4px 12px;
        background: #f4f6f8;
      }
    }
  }
}
/// pulled out of the specific table class so the new UI could take advantage of the header sorting
.header-row {
  text-transform: uppercase;
  a.sort-field {
    cursor: pointer;
    user-select: none;
    color: inherit;
    white-space: nowrap;
    i {
      color: #ccc;
    }
  }
  a.sort-field:hover {
    text-decoration: none;
    i {
      color: #0088cc;
    }
  }
  a.sort-field-active {
    i {
      color: black;
    }
  }
}

.pages.show {
  .course-title {
    display: none;
    font-size: 1.8em;
    font-weight: bold;
    line-height: 30px;
    margin: 0;
    color: #666;
  }
  .page-title {
    font-size: 2.5em;
    font-weight: 200;
    margin: 15px 0;
    color: #666;
  }
  .header-bar {
    .publish-button {
      margin: 0 12px 0 0;
    }
    .front-page.label {
      margin: 6px 12px 6px 0;
    }
    .published, .unpublished {
      display: inline-block;
      margin: 6px 8px 6px 5px;
    }
  }
  .locked-alert ul {
    margin: 4px 0 6px 25px;
  }
  .show-content {
    word-wrap: break-word;
    overflow-x: auto;
    box-sizing: border-box;
    padding: 0 $ic-sp;
    @include breakpoint(desktop) { padding: 0 $ic-sp*2 0 $ic-sp; }
  }
  .floating_links {
    margin-right: 15px;
  }
  .public-license {
    margin-left: 15px;
    margin-bottom: 15px;
  }
}

.pages.show.home {
  .course-title {
    display: block;
  }
  .page-title {
    display: none;
  }
  .show-content {
    padding-top: 25px;
  }
}

.pages.edit {
  .form-actions {
    padding-left: 1em;
  }
  .edit-form {
    margin: 0;
    .edit-content {
      padding: 1em;
      .edit-header {
        position: relative;
        margin-bottom: 1em;
      }
      .edit-header h2 {
        margin: 0;
      }
      .switch_views_container {
        display: flex;
        justify-content: flex-end;
      }
      .body {
        width: 98.5%;
      }
      .mceLayout {
        margin: 0;
      }
      .options {
        margin-top: 1em;
      }
    }
    .form-actions {
      margin-top: 0;
      margin-bottom: 0;
    }
  }
}

.pages.show.revisions {
  #wiki_page_revisions {
    position: relative;
    @include breakpoint(desktop) {
      min-height: 502px;
    }
  }
  .show-content {
    @include breakpoint(desktop) {
      margin-right: $revision-sidebar-width;
    }
  }
  .show-revisions {
    border-bottom: 1px solid $ic-border-light;
    @include breakpoint(desktop) {
      border-bottom: none;
      position: absolute;
      top: 0;
      right: 0;
      width: $revision-sidebar-width;
      aside {
        width: $revision-sidebar-width;
        position: fixed;
        padding-top: $ic-sp*2;
      }
    }

    .revision-history {
      @include fontSize($ic-font-size--small);
      position: relative;
      font-weight: bold;
      margin-bottom: $ic-sp;
      @include fontSize($ic-font-size--small);
    }
    .revision-history .close-button {
      position: absolute;
      top: 3px;
      bottom: 3px;
      right: 3px;
      width: 42px;
      text-align: center;
      color: dimgrey;
      &:hover {
        color: $ic-brand-primary;
      }
      i.icon-x {
        position: absolute;
        top: 50%;
        margin-top: -8px;
        right: 13px;
      }
    }
    ul.revisions-list {
      margin: 0;
      overflow-y: auto;
    }
  }
  .revision {
    list-style-type: none;
    overflow: hidden;
    // height and transitions
    height: 34px;
    transition: height 400ms;

    border-left: 2px solid transparent;

    &.selected, &.latest {
      height: 56px;
      transition: height 400ms;
    }
    .revision-content {
      padding: 7px 8px;
      @include fontSize($ic-font-size--xsmall);

      .revision-details {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 12px;
        color: #333;
      }
    }
    &:not(.selected):hover {
      border-left-color: $ic-link-color;
      .revision-content {
        cursor: pointer;
      }
    }

    .revision-actions {
      margin-top: 2px;
      font-style: italic;
      color: $revision-sidebar-dimmed-color;
    }
    .revision-actions a.restore-link {
      font-style: normal;
      cursor: pointer;
    }
    &.selected {
      border-left-color: $ic-link-color;
      background: $ic-bg-light-primary;
    }
  }
  .revision-nav-buttons {
    position: relative;
    height: $ic-sp*3;

    a {
      user-select: none;
      text-transform: uppercase;
      font-weight: bold;
    }
    a:hover {
      text-decoration: none;
      cursor: pointer;
      //color: $revision-button-hover-color;
      border-radius: 3px;
    }
    .prev-button {
      position: absolute;
      left: 0;
      top: 0
    }
    .next-button {
      position: absolute;
      right: 0;
      top: 0;
    }
  }
}

@media print {
  #breadcrumbs, .header-bar-outer-container {
    display: none;
  }
  .pages.show.revisions {
    .show-revisions {
      display: none;
    }
    .show-content {
      margin-right: 0;
    }
  }
}

#wiki_show_view_main {
  overflow: auto;
}

#last_edited_by {
  border: solid #eee;
  border-width: 0 0 1px 0;
  font-size: 0.8em;
  margin-bottom: 10px;
  margin-right: 2px;
  h3, .h3 {
    margin: 0px 20px 10px;
    font-size: 1.5em;
    color: #444;
  }
}

#page_history {
  float: right;
}

// this is to fix a bug that was reported that if you shrink your browser window width to something small
// that it would just cut off the right side of the tiny WYSIWYG editor box and make it dissapear beind the right side.
#wiki_page_body_parent.mceEditor {
  display: block;
  overflow: auto;
}
